package com.hmall.search.controller;


import cn.hutool.extra.spring.SpringUtil;
import com.hmall.api.item.dto.ItemDTO;
import com.hmall.search.domain.dto.PageDTO;

import com.hmall.search.domain.query.ItemPageQuery;
import com.hmall.search.service.ISearchService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Api(tags = "搜索相关接口")
@RestController
@RequestMapping("/search")
@RequiredArgsConstructor
public class SearchController {

    private final ISearchService iSearchService;
    private final SpringUtil springUtil;


    @ApiOperation("搜索商品")
    @GetMapping("/list")
    public PageDTO<ItemDTO> search(ItemPageQuery query) throws Exception {
        // 分页查询

        PageDTO<ItemDTO> result = iSearchService.search(query);
        // 封装并返回
        return result;
    }
    @ApiOperation("搜索的过滤项")
    @PostMapping("/filters")
    public Map<String, List<String>> filters(@RequestBody ItemPageQuery query)  throws Exception {

        Map<String, List<String>> result = iSearchService.filters(query);

        // 封装并返回
        return result;
    }
    @ApiOperation("初始化es中的数据")
    @GetMapping("/initEs")
    public String searchall()  throws  Exception{

        // 分页查询
        iSearchService.initEs();
        // 封装并返回
        return "true";
    }
}
